/**
 * Author :tianhongyu
 * Date : 2018/4/29 16:52
 */
package com.tian.source.controller;

import com.tian.core.beans.ResultBean;
import com.tian.core.page.Page;
import com.tian.source.model.Department;
import com.tian.source.model.vo.DepartmentVo;
import com.tian.source.service.DepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/department")
public class DepartmentController {

    @Autowired
    private DepartmentService departmentService;

    /**
     * 添加部门
     * @param department
     * @return
     */
    @PostMapping("/addDept")
    public ResultBean<String> addDepartment(Department department){
        departmentService.add(department);
        return new ResultBean<>("添加成功");
    }

    /**
     * 查询所有部门
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/getAllByPage")
    public ResultBean<Page<List<DepartmentVo>>> getAllByPage(Integer pageNum, Integer pageSize, Department department){
        Page page = new Page(pageNum,pageSize);
        return new ResultBean<>(departmentService.findDepartmentByPage(page,department));
    }

    /**
     * 获取部门信息通过Id
     * @param departmentId
     * @return
     */
    @GetMapping("/getInfoById")
    public ResultBean<Department> getInfo(Integer departmentId){
        return new ResultBean<>(departmentService.findById(departmentId));
    }

    /**
     * 修改部门信息
     * @param department
     * @return
     */
    @PostMapping("/updateDepartment")
    public ResultBean update(Department department){
        departmentService.modifyById(department);
        return new ResultBean<>();
    }

    /**
     * 职位添加--获取所有部门
     * @return
     */
    @GetMapping("/getAll")
    public ResultBean<List<Department>> getAll(){
        return new ResultBean<>(departmentService.getAll());
    }
}
